import React, { useReducer } from 'react'

const App = () => {
	const reducer = (state, action) => {
		switch (action.type) {
			case 'increment':
				return state + 1
			case 'decrement':
				return state - 1
		}
	}
	// 第一个参数就是上面的方法
	// 第二个参数是 count 的值
	const [count, dispatch] = useReducer(reducer, 0)
	return (
		<div>
			<button
				onClick={() => {
					dispatch({ type: 'increment' })
				}}
			>
				+1
			</button>
			<span>{count}</span>
			<button
				onClick={() => {
					dispatch({ type: 'decrement' })
				}}
			>
				-1
			</button>
		</div>
	)
}
export default App
